package se.cbb.scripts;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;

import se.cbb.misc.Sequence;
import se.cbb.misc.SequenceFileWriter;
import se.cbb.misc.SimpleFileIO;

public class FERMDomainChecker {

	public static void main(String[] args) {
		try {
			String path = "/Users/rhali/Movies/Projects/Kindlin3/Blast Hits/";
			
			SimpleFileIO reader = new SimpleFileIO();
			reader.readSequenceFile(path, "FERMDomainContiaingSequences.fasta");
			ArrayList<Sequence> sequences = reader.getSequences();
			
			BufferedReader bufferedreader = new BufferedReader(new FileReader(path + "FERMDomainSequenceInfo.txt"));
			String str = bufferedreader.readLine();
			while ((str = bufferedreader.readLine()) != null) {
				String[] strArr = str.split("\t");
				String[] strArr1 = strArr[0].split(" ");
				for(int i = 0; i < sequences.size(); i++) {
					String header = sequences.get(i).getIdentifier();
					String strArr2[] = header.split("\\|");
					if(strArr2[1].equals(strArr1[2])) {
						String seq = sequences.get(i).getSequence().substring(Integer.parseInt(strArr[3]), Integer.parseInt(strArr[4]));
						SequenceFileWriter.writeAndAppendSequenceInFasta(path, "FERMDomainSequences.fasta", new Sequence(sequences.get(i).getIdentifier(), seq));
					}
				}
			}
			
			bufferedreader.close();
			
/*			for(int i = 0; i < sequences.size(); i++) {
				String header = sequences.get(i).getIdentifier();
				String strArr[] = header.split("\\|");
				String spec = strArr[4].split("\\[")[1];
				SequenceFileWriter.writeAndAppendLine(path, "FERMDomainContainingHeaders.txt", strArr[0] + "\t" + strArr[1] + "\t" + strArr[2] + "\t" + strArr[3] + "\t" + strArr[4] + "\t" + spec);
			}
			
	/*		BufferedReader bufferedreader = new BufferedReader(new FileReader(fileName));
			String str;
			while ((str = bufferedreader.readLine()) != null) {
				String[] strArr1 = str.split(" ");
				System.out.println(strArr1[2]);
				for(int i = 0; i < sequences.size(); i++) {
					String[] strArr = sequences.get(i).getIdentifier().split("\\|");
					if(strArr[1].equals(strArr1[2])) {
						SequenceFileWriter.writeAndAppendSequenceInFasta(path, "FERMDomainContiaingSequences.fasta", sequences.get(i));
					}
				}
			}
			
			bufferedreader.close();*/
		} catch (Exception e) {
			System.out.println("Error : " + e.getMessage());
		}

	}

}
